//
//  UIBarButtonItem+Extension.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/20/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit
extension UIBarButtonItem{
    convenience init(title: String? = nil, imgName: String? = nil, target: AnyObject?, action: Selector){
        
        self.init()
        let btn: UIButton = UIButton()
        if let tit = title {
            btn.setTitle(tit, forState: UIControlState.Normal)
            btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
            btn.setTitleColor(UIColor.grayColor(), forState: UIControlState.Disabled)
        }
        if let img = imgName {
            btn.setImage(UIImage(named: img), forState: UIControlState.Normal);
        }
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        
        btn.sizeToFit()
        self.customView = btn
    }
}